import { setUserInfo, getUserInfo, setTokenKey, getTokenKey } from "../../utils/auth";

const app = getApp();
Page({
  data: {
    userList: [],
    currentUser: null,
    currentUserType:''
  },

  onLoad(options) {
    this.setData({
      currentUser: getUserInfo(),
      currentUserType: options.userType
    })
    this.getUserList(options.companyId)
  },

  // 通过companyId 获取userList
  getUserList(companyId){
    app.call({
      path:`/users/company/${companyId}`,
      method: 'get',
      header: {
        'X-WX-SERVICE': 'fire-assistant-s',
        'tokens': getTokenKey()//必须添加#######
      }
    }).then(res=>{
      // 需要去除当前user
      let currentUser = getUserInfo().user
      const userList = res.filter(item => {
        return item.id !== currentUser.id
      })
      this.setData({userList})
    }) 
  }
})